<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改采集设备')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-device-edit" th:object="${basicDevice}">
            <input name="deviceId" id="deviceId" th:field="*{deviceId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">IMEI号：</label>
                    <div class="col-sm-8">
                        <input name="deviceImei" id="deviceImei" th:field="*{deviceImei}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">设备类型：</label>
                    <div class="col-sm-8">
                        <select name="deviceType" class="form-control m-b">
                            <option value="DTU" th:field="*{deviceType}">DTU模组</option>
                            <option value="4G" th:field="*{deviceType}">4G模组</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">运营商：</label>
                    <div class="col-sm-8">
                        <select name="deviceOperator" class="form-control m-b" th:with="type=${@dict.getType('operator_type')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{deviceOperator}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/device";
        $("#form-device-edit").validate({
            onkeyup: false,
            rules:{
                deviceImei:{
                    remote: {
                        url: prefix + "/checkDeviceImeiUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "deviceImei" : function() {
                                return $.common.trim($("#deviceImei").val());
                            },
                            "deviceId" : function() {
                                return $("#deviceId").val();
                            }
                        }
                    }
                }
            },
            messages: {
                "deviceImei": {
                    remote: "imei号已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-device-edit').serialize());
            }
        }
    </script>
</body>
</html>